package ca.seia.comp6521.a1;

import java.io.IOException;

import ca.seia.comp6521.a1.externalmergesort.ExternalMergeSortExecutionController;
import ca.seia.comp6521.a1.externalmergesort.PhaseIIStatistics;
import ca.seia.comp6521.a1.externalmergesort.PhaseIStatistics;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ExternalMergeSortExecutionController mergeSortExecutionController = new ExternalMergeSortExecutionController();
		try {
			System.out.println("--------------Started Phase I--------------");
			PhaseIStatistics phaseIResult = mergeSortExecutionController.ExecutePhaseI();
			System.out.println("--------------End of Phase I--------------");
			
			if ( phaseIResult.getSortedSubListsFilePaths().size() > 1) {
				System.out.println("--------------Started Phase II--------------");
				PhaseIIStatistics phaseIIStatistics = mergeSortExecutionController.ExecutePhaseII(phaseIResult);
				System.out.println(phaseIIStatistics);
				System.out.println("--------------End of Phase II--------------.");
				System.out.println("Total Time for sorting the file : " + (phaseIResult.getExecutionTime() + phaseIIStatistics.getExecutionTime()) + " ms");			
			} else {
				System.out.println("No Phase II is required");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
